package com.yt.service.impl;

import com.yt.entity.Author;
import com.yt.entity.CommonResult;
import com.yt.entity.Novel;
import com.yt.mapper.AuthorMapper;
import com.yt.service.AuthorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class AuthorServiceImpl implements AuthorService {
    @Resource
    AuthorMapper authorMapper;
    @Resource
    RestTemplate restTemplate;
    public static final String url="http://EUREKA-NOVEL";
    @Override
    public Author getAuthorById(Integer id) {
        return authorMapper.getAuthorById(id);
    }

    @Override
    public List<Novel> getNovelsByAid(Integer aid) {
        CommonResult<List<Novel>> result=restTemplate.getForObject(url+"/novel/"+aid,CommonResult.class);
        log.info(result.toString());
        return result.getT();
    }

}
